package top.heue.epro.service;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;

@TargetApi(Build.VERSION_CODES.N)
public class StatusBarService extends TileService {
    @Override
    public void onTileAdded() {
        getQsTile().updateTile();
        //Toast.makeText(getApplicationContext(), "添加了", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onTileRemoved() {
        //Toast.makeText(getApplicationContext(), "删除了", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick() {
        //this.requestListeningState(this,new ComponentName("top.heue.statebar", StatusBarService.class.getName()));
        handleStatusChanged();
        //Toast.makeText(getApplicationContext(), "点击了", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStartListening() {
        //Toast.makeText(getApplicationContext(), "下拉了", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStopListening() {
        //Toast.makeText(getApplicationContext(), "上滑了", Toast.LENGTH_SHORT).show();
    }

    private void handleStatusChanged() {
        Tile tile = getQsTile();
        if (tile == null) {
            return;
        }
        Intent intent = new Intent(this, WindowService.class);
        switch(tile.getState()) {
            case Tile.STATE_ACTIVE:
                stopService(intent);
                tile.setState(Tile.STATE_INACTIVE);
                break;
            case Tile.STATE_INACTIVE:
                startService(intent);
                tile.setState(Tile.STATE_ACTIVE);
                break;
        }
        tile.updateTile();
    }


}